package eproject.mm.com.projectsupervision.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.liji.imagezoom.util.ImageZoom;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;
import java.util.Map;

import eproject.mm.com.projectsupervision.PrjApplication;
import eproject.mm.com.projectsupervision.R;

public class BaseRecyclerImageViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private LayoutInflater mLayoutInflater;
    private Context context;
    //private List<Map> lists;
    private List<String> smallImages;
    private List<String> bigImages = null;

    private ImageLoader imageLoader = ImageLoader.getInstance();

    public BaseRecyclerImageViewAdapter(Context context, List<String> smallImages, List<String> bigImages){
        this.smallImages = smallImages;
        this.bigImages = bigImages;
        this.context = context;
        mLayoutInflater = LayoutInflater.from(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ItemViewHolder(mLayoutInflater.inflate(R.layout.rv_item_report_image, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        String image = (String)smallImages.get(position);
        String url = "http://"+ PrjApplication.getInstance().getServerIp()+":"+PrjApplication.getInstance().getServerPort() + image;

        imageLoader.displayImage(url, ((ItemViewHolder) holder).iv_image);
        ((ItemViewHolder) holder).iv_image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                ImageZoom.show(context, bigImages.get(position), bigImages);
            }
        });
    }


    @Override
    public int getItemCount() {
        return smallImages == null ? 0 : smallImages.size();
    }

    public static class ItemViewHolder extends RecyclerView.ViewHolder{
        ImageView iv_image;

        public ItemViewHolder(View itemView) {
            super(itemView);
            iv_image = itemView.findViewById(R.id.iv_image);
        }
    }

}